.TH std::to_wstring 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::to_wstring \- std::to_wstring

.SH Synopsis
   Defined in header <string>
   std::wstring to_wstring( int value );                \fB(1)\fP \fI(since C++11)\fP
   std::wstring to_wstring( long value );               \fB(2)\fP \fI(since C++11)\fP
   std::wstring to_wstring( long long value );          \fB(3)\fP \fI(since C++11)\fP
   std::wstring to_wstring( unsigned value );           \fB(4)\fP \fI(since C++11)\fP
   std::wstring to_wstring( unsigned long value );      \fB(5)\fP \fI(since C++11)\fP
   std::wstring to_wstring( unsigned long long value ); \fB(6)\fP \fI(since C++11)\fP
   std::wstring to_wstring( float value );              \fB(7)\fP \fI(since C++11)\fP
   std::wstring to_wstring( double value );             \fB(8)\fP \fI(since C++11)\fP
   std::wstring to_wstring( long double value );        \fB(9)\fP \fI(since C++11)\fP

   Converts a numeric value to std::wstring.

   Let buf be an internal to the conversion functions buffer,
   sufficiently large to contain the result of conversion.

   1) Converts a signed decimal integer to a wide string as if by
   std::swprintf(buf, sz, L"%d", value).
   2) Converts a signed decimal integer to a wide string as if by
   std::swprintf(buf, sz, L"%ld", value).
   3) Converts a signed decimal integer to a wide string as if by
   std::swprintf(buf, sz, L"%lld", value).
   4) Converts an unsigned decimal integer to a wide string as if by      (until C++26)
   std::swprintf(buf, sz, L"%u", value).
   5) Converts an unsigned decimal integer to a wide string as if by
   std::swprintf(buf, sz, L"%lu", value).
   6) Converts an unsigned decimal integer to a wide string as if by
   std::swprintf(buf, sz, L"%llu", value).
   7,8) Converts a floating point value to a wide string as if by
   std::swprintf(buf, sz, L"%f", value).
   9) Converts a floating point value to a wide string as if by
   std::swprintf(buf, sz, L"%Lf", value).
   1-9) Converts a numeric value to a wide string as if by                (since C++26)
   std::format(L"{}", value).

.SH Parameters

   value - a numeric value to convert

.SH Return value

   A wide string holding the converted value.

.SH Exceptions

   May throw std::bad_alloc from the std::wstring constructor.

.SH Example


// Run this code

 #include <iostream>
 #include <string>

 int main()
 {
     for (const double f : {23.43, 1e-9, 1e40, 1e-40, 123456789.0})
         std::wcout << "std::wcout: " << f << '\\n'
                    << "to_wstring: " << std::to_wstring(f) << "\\n\\n";
 }

.SH Output:

 std::wcout: 23.43
 to_wstring: 23.430000

 std::wcout: 1e-09
 to_wstring: 0.000000

 std::wcout: 1e+40
 to_wstring: 10000000000000000303786028427003666890752.000000

 std::wcout: 1e-40
 to_wstring: 0.000000

 std::wcout: 1.23457e+08
 to_wstring: 123456789.000000

.SH See also

   to_string converts an integral or floating-point value to string
   \fI(C++11)\fP   \fI(function)\fP
